
import java.util.Scanner;

public class TJU_1909 {
    static int stepsToEnd;
    public static int[][] loopMat;
    public static char[][] maze;
    public static int r;
    public static int c;

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int rows = sc.nextInt();
            int columns = sc.nextInt();
            int entryColumn = sc.nextInt() - 1;
            sc.nextLine();
            c = entryColumn;
            r = 0;
            stepsToEnd = 0;
            if (rows == 0) {
                return;
            }
            loopMat = new int[rows][columns];
            maze = new char[rows][columns];
            for (int i = 0; i < rows; i++) {
                maze[i] = sc.nextLine().toCharArray();
            }
            if (isExit(rows * columns)) {
                System.out.println(stepsToEnd + " step(s) to exit");
            } else {
                c = entryColumn;
                r = 0;
                stepsToEnd = 0;
                int loopSize = loopSize();

                System.out.println(stepsToEnd + " step(s) before a loop of "
                        + loopSize + " step(s)");
            }
        }
    }

    public static void move () {
        char cur = maze[r][c];
        if (cur == 'N') {
            r--;
        } else if (cur == 'S') {
            r++;
        } else if (cur == 'W') {
            c--;
        } else {
            c++;
        }
    }

    public static boolean isExit (int n) {
        for (int i = 0; i < 5 * n; i++) {
            try {
                move();
                stepsToEnd++;
            } catch (ArrayIndexOutOfBoundsException e) {
                return true;
            }
        }
        return false;
    }

    public static boolean loopFound () {
        for (int i = 0; i < maze.length; i++) {
            for (int j = 0; j < maze[0].length; j++) {
                if (loopMat[i][j] == 3) {
                    return true;
                }
            }
        }
        return false;
    }

    public static int loopSize () {
        while (!loopFound()) {
            loopMat[r][c]++;
            move();
        }
        int l = 0;
        for (int i = 0; i < maze.length; i++) {
            for (int j = 0; j < maze[0].length; j++) {
                if (loopMat[i][j] == 3 || loopMat[i][j] == 2) {

                    l++;
                }
                if (loopMat[i][j] == 1) {
                    stepsToEnd++;
                }
            }
        }
        return l;
    }
}
